import random
from datetime import datetime
import urllib.request
import requests
import lxml.html
import telebot
from telebot import types

bot = telebot.TeleBot('ur token')
@bot.message_handler(content_types=['text'])

def gethttp(message):
    global ip_range
    try:
        if message.text == "/full_list":
            ip_txt = open("ip.txt", 'rb')
            bot.send_document(message.chat.id, ip_txt)
            current_datetime = datetime.now()
            bot.send_message(message.from_user.id,"Актуален на текущий момент ("+str(current_datetime)+")") 
        if message.text != "/full_list":
            ip_range = int(message.text)
            while ip_range != 0:
                rand_ip = random.choice(open("ip.txt").readlines())
                url = 'http://'+rand_ip.strip()
                print(url)
                try:
                    t = lxml.html.parse(url)
                    bot.send_message(message.from_user.id, "http://" + rand_ip + "\n"+ "title: " + t.find(".//title").text)
                    ip_range -= 1
                except Exception as err:
                    bot.send_message(message.from_user.id, "http://" + rand_ip + "\n"+ "title: None")
    except Exception as err:
        bot.send_message(message.from_user.id,"Хули ты вводишь?!")
